package com.lmx.project.controlle;

import com.lmx.project.common.BaseResponse;
import com.lmx.project.common.ResultUtils;
import com.lmx.project.service.FileService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController()
@RequestMapping("file")
public class FileController {

    @Resource
    private FileService fileService;


    /**
     * 增加文件
     */
    @PostMapping
    public BaseResponse<Boolean> addFile(MultipartFile file, String dir) {
        fileService.saveMultipartFile(file, dir);
        return ResultUtils.success(true);
    }


    /**
     * 删除文件
     */
    @PostMapping("delete")
    public BaseResponse<Boolean> delteFile(@RequestBody String filepath) {
        fileService.removeFile(filepath);
        return ResultUtils.success(true);
    }



    /**
     * 批量删除文件
     */
    @DeleteMapping("list")
    public BaseResponse<Boolean> deleteFileList(List<String> filepathlist) {
        fileService.removeFileList(filepathlist);
        return ResultUtils.success(true);
    }


    /**
     * 获取前缀
     */
    @GetMapping("pre")
    public BaseResponse<String> getPreUrl() {
        return ResultUtils.success(fileService.getPreurl());
    }


}
